#pragma once

#include <QtWidgets/QMainWindow>
#include <QTimer>
#include <QImage>
#include <QPainter>
#include <memory>
#include <opencv2/opencv.hpp>
#include "ui_model_loading.h"

class model_loading : public QMainWindow
{
	Q_OBJECT

public:
	model_loading(QWidget* parent = nullptr);
	~model_loading();

private:
	QImage concatenateImagesHorizontally(const QImage& img1, const QImage& img2);
	double BGRtoTemp(double MinTemp, double MaxTemp, const cv::Vec3b& Color);
	double image_to_temperature(const cv::Mat& image);
	void check_crust(const cv::Mat& image_temperature, cv::Mat& copy);
	void StandardizeBGR(cv::Vec3b& color);
	QImage MatToQImage(const cv::Mat& mat);

private slots:
	void update_simulation_pic();
	void update_camera_pic();
	void update_switching();
	cv::Mat process_pic(cv::Mat& src, int method);

private:
	Ui::model_loadingClass ui;
	QTimer timer_simulation_pic;
	QTimer timer_camera_pic;
	QTimer timer_stiching;

	std::unique_ptr<QImage> img_simulation_front = nullptr;
	std::unique_ptr<QImage> img_simulation_bank = nullptr;

	QImage concatenated_image;

	std::unique_ptr<QImage> img_camera1 = nullptr;
	std::unique_ptr<QImage> img_camera2 = nullptr;

	int simulation_pic_start = 1901;
	int camera_pic_start = 0;
	const uchar MisColorThu = 150;

	cv::Mat zero_count;
	const int time_threshold = 240;
};